<?php
class Model_Link extends Zend_Db_Table_Abstract{
	protected $_name='links';
	
	public function createLink($title,$url,$description,$category,$name,$email,$v_code){
		$row=$this->createRow();
		$row->title=$title;
		$row->url=$url;
		$row->description=$description;
		$row->category=$category;
		$row->name=$name;
		$row->email=$email;		
		$row->v_code=$v_code;
		return $row->save();
	}
	public function verifyLink($v_code){
		$select=$this->select();
		$select->where('v_code'.'=?',$v_code);
		$row=$this->fetchRow($select);
		if( $row && $row->status==0){
			$row->status=1;
			return $row->save();
		}		
	}
	public function activateLink($id){
		$row=$this->find($id)->current();
		$row->status=2;
		return $row->save();	
	}
	public function deleteLink($id){
		$row=$this->find($id)->current();
		$row->delete();
	}
	public function fetchLink($id){
		$row=$this->find($id)->current();
		return $row;
	}
	public function fetchLinksPaginatorAdapter($filters=array(),$sortField=null){
		$select=$this->select();
		if(count($filters)>0){
			foreach($filters as $field=>$filter){
				$select->where($field.'=?',$filter);
			}
		}
		//add sort field which is set
		if(null!=$sortField){
			$select->order($sortField);
		}
		//create a new instance of the paginator adapter and return
		$adapter=new Zend_Paginator_Adapter_DbTableSelect($select);
		return $adapter;	
	}
}
?>